package polymorphism;

import java.util.ArrayList;
import java.util.List;

//抽象类 关键字abstract
abstract class Animal{
    abstract public void shout();  //抽象方法
}
class Dog extends Animal{
     public void shout(){
           System.out.println("汪汪……");
      }
}
class Pig extends Animal{
    public void shout(){
         System.out.println("喵喵……");
      }
}

public class Test{
	public static void main(String[] args) {
		List<Animal> animals = createAnimals();
		for(Animal a : animals) {
			a.shout();
		}
		//Animal a = new Dog();
		//a.shout();
	}
	static List<Animal> createAnimals(){
		List<Animal> rst = new ArrayList<Animal>();
		rst.add(new Pig());
		rst.add(new Dog());
		rst.add(new Pig());
		return rst;
	}
}